﻿package Interface.ShopClasses
{	
	import Core.Game;

	import flash.display.MovieClip;	
	import flash.display.FrameLabel;

	public class ShopItem extends MovieClip
	{
		protected var FGlobalID:int;
		protected var FType:int;		
		protected var FPrice:int;
		protected var FGraphic:int;
		protected var FPRofileGraphic:int;		
		protected var FBonus:Number;
		protected var FName:String;	
		protected var FIcons:MovieClip;
		
		public function ShopItem():void 
		{
			FType = -1;
			FPrice = 0;
			FBonus = new Number();
			FName = 'No name';
			FPRofileGraphic = 1;
			FGraphic = 1;
			
			FIcons = getChildByName('Items') as MovieClip;
			
			useHandCursor = true;
			buttonMode = true;
		}
		
		public function set GlobalID(AGlobalID:int):void
		{
			FGlobalID = AGlobalID;			
		}
		
		public function get GlobalID():int
		{
			return FGlobalID;
		}
		
		public function set Type(AType:int):void
		{
			FType = AType;			
		}
		
		public function get Type():int
		{
			return FType;
		}
		
		public function set Price(APrice:int):void
		{
			FPrice = APrice;
		}
		
		public function get Price():int
		{
			return FPrice;
		}
		
		public function set Bonus(ABonus:Number):void
		{
			FBonus = ABonus;
		}
		
		public function get Bonus():Number
		{
			return FBonus;
		}
		
		public function set Graphic(AGraphic:int):void
		{
			FGraphic = AGraphic;
			FIcons.gotoAndStop(FGraphic);
		}
		
		public function get Graphic():int
		{
			return FGraphic;
		}
		
		public function get ProfileGraphic():int
		{
			return FPRofileGraphic;
		}
		
		public function set ProfileGraphic(AGraphic:int):void
		{
			FPRofileGraphic = AGraphic;
		}
		
		public function set Name(AName:String):void
		{
			FName = AName;
		}
		
		public function get Name():String
		{
			return FName;
		}
		
		public function set Description(ADescription:String):void
		{			
		}
		
		public function get Description():String
		{
			if(Price > 0)
				return Name + '. ' + 'Цена: ' + Price.toString() + ', бонус: X' + Bonus.toString();
			else
				return Name + '. ' + 'Цена: ' + Price.toString() + '(товар уже приобретен)' + ', бонус: X' + Bonus.toString();
		}
		
		public function Buy(AGame:Game):void
		{
			AGame.User.Money -= Price;
			AGame.Profile.ChangeItem(this);
			Price = 0;
		}
		
		public function FrameByName(AName:String):int
		{
			var vResult:int = -1;
			for each(var vLabel:FrameLabel in FIcons.currentLabels)
			{
				if(vLabel.name == AName)
				{
					vResult = vLabel.frame;
					break;
				}
			}
			return vResult;
		}
	}	
}
